package com.itheima.book.manager.service;

import com.itheima.book.manager.dao.BookDao;
import com.itheima.book.manager.dao.BookDao2;
import com.itheima.book.manager.domain.Book;

public class BookService {
    private BookDao2 bookDao = new BookDao2();
    public boolean addBook(Book book){
        bookDao.addBook(book);
        return true;
    }

    public boolean idExistsBookId(String bookId){
        Book[] allBooks = bookDao.getAllBooks();
        for (int i = 0; i < allBooks.length; i++) {
            if (allBooks[i] != null){
                if (allBooks[i].getBookID().equals(bookId)){
                    return true;
                }
            }
        }
        return false;
    }

    public Book[] findAll(){
        Book[] allBooks = bookDao.getAllBooks();
        return allBooks;
    }

    public void deleteByBookId(String bookId){
        bookDao.deleteByBookId(bookId);
    }

    public void updateBookByBookId(Book book){
        bookDao.updateBookByBookId(book);
    }
}
